package com.mayuanfei.springioc.service;

import com.mayuanfei.springioc.domain.SysUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * User管理服务类
 *
 * @author 老马
 * @date 2023-02-27 13:58
 */
@SuppressWarnings("all")
@Component
public class SysUserManager2 {

    @Value("${user.id}")
    private String userId;
    @Value("${user.name}")
    private String userName;
    @Value("${user.address}")
    private String address;
    @Value("${ip}")
    private String ip;
    @Value("${port}")
    private String port;
    // 注入系统属性
    @Value("#{systemProperties['os.name']}")
    private String osName;
    // 注入表达式结果
    @Value("#{T(java.lang.Math).random()*1000}")
    private double randomNum;
    // 注入其他bean执行方法的结果
    @Value("#{user1.userRandomName}")
    private String fromAnotherBean;

    public void showUser() {
        System.out.println(ip+":"+port);
        System.out.println("操作系统:"+osName);
        System.out.println("随机数:"+randomNum);
        System.out.println("其他bean的方法:"+fromAnotherBean);
        SysUser user = new SysUser();
        user.setUserId(""+userId);
        user.setUserName(userName);
        user.setAddress(address);
        System.out.println(user);
    }
}